package doan.quanlycanbo.portlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Layout;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

import doan.quanlycanbo.portlet.model.capuy;
import doan.quanlycanbo.portlet.model.chucvu;
import doan.quanlycanbo.portlet.model.danhhieu;
import doan.quanlycanbo.portlet.model.dantoc;
import doan.quanlycanbo.portlet.model.dienbienhocham;
import doan.quanlycanbo.portlet.model.dienbienhocvi;
import doan.quanlycanbo.portlet.model.dienbienluong;
import doan.quanlycanbo.portlet.model.donvi;
import doan.quanlycanbo.portlet.model.giaoducphothong;
import doan.quanlycanbo.portlet.model.hesoluong;
import doan.quanlycanbo.portlet.model.hocham;
import doan.quanlycanbo.portlet.model.hocvi;
import doan.quanlycanbo.portlet.model.hoso;
import doan.quanlycanbo.portlet.model.khoidonviquanly;
import doan.quanlycanbo.portlet.model.ngachluong;
import doan.quanlycanbo.portlet.model.quatrinhdinuocngoai;
import doan.quanlycanbo.portlet.model.quatrinhnghiencuu;
import doan.quanlycanbo.portlet.model.tongiao;
import doan.quanlycanbo.portlet.model.xuatthan;
import doan.quanlycanbo.portlet.model.impl.capuyImpl;
import doan.quanlycanbo.portlet.model.impl.chucvuImpl;
import doan.quanlycanbo.portlet.model.impl.danhhieuImpl;
import doan.quanlycanbo.portlet.model.impl.dantocImpl;
import doan.quanlycanbo.portlet.model.impl.dienbienhochamImpl;
import doan.quanlycanbo.portlet.model.impl.dienbienhocviImpl;
import doan.quanlycanbo.portlet.model.impl.dienbienluongImpl;
import doan.quanlycanbo.portlet.model.impl.donviImpl;
import doan.quanlycanbo.portlet.model.impl.giaoducphothongImpl;
import doan.quanlycanbo.portlet.model.impl.hesoluongImpl;
import doan.quanlycanbo.portlet.model.impl.hochamImpl;
import doan.quanlycanbo.portlet.model.impl.hocviImpl;
import doan.quanlycanbo.portlet.model.impl.hosoImpl;
import doan.quanlycanbo.portlet.model.impl.khoidonviquanlyImpl;
import doan.quanlycanbo.portlet.model.impl.ngachluongImpl;
import doan.quanlycanbo.portlet.model.impl.quatrinhdinuocngoaiImpl;
import doan.quanlycanbo.portlet.model.impl.quatrinhnghiencuuImpl;
import doan.quanlycanbo.portlet.model.impl.tongiaoImpl;
import doan.quanlycanbo.portlet.model.impl.xuatthanImpl;
import doan.quanlycanbo.portlet.service.capuyLocalServiceUtil;
import doan.quanlycanbo.portlet.service.chucvuLocalServiceUtil;
import doan.quanlycanbo.portlet.service.danhhieuLocalServiceUtil;
import doan.quanlycanbo.portlet.service.dantocLocalServiceUtil;
import doan.quanlycanbo.portlet.service.dienbienhochamLocalServiceUtil;
import doan.quanlycanbo.portlet.service.dienbienhocviLocalServiceUtil;
import doan.quanlycanbo.portlet.service.dienbienluongLocalServiceUtil;
import doan.quanlycanbo.portlet.service.donviLocalServiceUtil;
import doan.quanlycanbo.portlet.service.giaoducphothongLocalServiceUtil;
import doan.quanlycanbo.portlet.service.hesoluongLocalServiceUtil;
import doan.quanlycanbo.portlet.service.hochamLocalServiceUtil;
import doan.quanlycanbo.portlet.service.hocviLocalServiceUtil;
import doan.quanlycanbo.portlet.service.hosoLocalServiceUtil;
import doan.quanlycanbo.portlet.service.khoidonviquanlyLocalServiceUtil;
import doan.quanlycanbo.portlet.service.ngachluongLocalServiceUtil;
import doan.quanlycanbo.portlet.service.quatrinhdinuocngoaiLocalServiceUtil;
import doan.quanlycanbo.portlet.service.quatrinhnghiencuuLocalServiceUtil;
import doan.quanlycanbo.portlet.service.tongiaoLocalServiceUtil;
import doan.quanlycanbo.portlet.service.xuatthanLocalServiceUtil;
import doan.quanlycanbo.portlet.util.PortletKeysExt;

/**
 * Portlet implementation class ManageEmployee
 */
public class ManageEmployee extends MVCPortlet {
 
	/**
	 * 
	 * 	Cập nhật thông tin hồ sơ cán bộ
	 * 
	 */
	public void updateProfile(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException, ParseException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		Layout layout = themeDisplay.getLayout();
		long groupId = layout.getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		long userId = themeDisplay.getUserId();
		
		UploadPortletRequest uploadReq = PortalUtil.getUploadPortletRequest(req);
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		
		String idHoso = ParamUtil.getString(uploadReq, "idHoso");
//		long userIdAddProfile = ParamUtil.getLong(uploadReq, "userId");
//		User user = UserLocalServiceUtil.getUser(userIdAddProfile);
		
		// Get data form
		String hoten = ParamUtil.getString(uploadReq, "hoten");
		long shnv = ParamUtil.getLong(uploadReq, "sohieunv");
		String cmtnd = ParamUtil.getString(uploadReq, "cmtnd");
		String tenthuongdung = ParamUtil.getString(uploadReq, "tenthuongdung");
		String gioitinh = ParamUtil.getString(uploadReq, "gioitinh");
		
		String noisinh = ParamUtil.getString(uploadReq, "noisinh");
		String quequan = ParamUtil.getString(uploadReq, "quequan");
		String diachithuongtru = ParamUtil.getString(uploadReq, "diachithuongtru");
		String diachitamtru = ParamUtil.getString(uploadReq, "diachitamtru");
		String dienthoai = ParamUtil.getString(uploadReq, "dienthoai");
		String email = ParamUtil.getString(uploadReq, "email");
		String quocgia = ParamUtil.getString(uploadReq, "quocgia");
		
		String cntn1 = ParamUtil.getString(uploadReq, "cntn1");
		int namtn1 = ParamUtil.getInteger(uploadReq, "namtn1");
		String cntn2 = ParamUtil.getString(uploadReq, "cntn2");
		int namtn2 = ParamUtil.getInteger(uploadReq, "namtn2");
		String cntn3 = ParamUtil.getString(uploadReq, "cntn3");
		int namtn3 = ParamUtil.getInteger(uploadReq, "namtn3");
		
		String sDateDOB = uploadReq.getParameter("dayDOB") + "/" + uploadReq.getParameter("monthDOB") + "/" + uploadReq.getParameter("yearDOB");
		Date dateDOB = dateFormat.parse(sDateDOB);
		
		String sNgayVaoDang = uploadReq.getParameter("dayVaoDang") + "/" + uploadReq.getParameter("monthVaoDang") + "/" + uploadReq.getParameter("yearVaoDang");
		Date ngayVaoDang = new Date();
		boolean joinDate = ParamUtil.getBoolean(uploadReq, "joinDate");
		if(joinDate){
			ngayVaoDang = dateFormat.parse(sNgayVaoDang);
		}else{
			ngayVaoDang = null;
		}
		
		long madantoc = ParamUtil.getLong(uploadReq, "dantoc");
		long mahocham = ParamUtil.getLong(uploadReq, "hocham");
		long mahocvi = ParamUtil.getLong(uploadReq, "hocvi");
		long mahesoluong = ParamUtil.getLong(uploadReq, "hesoluong");
		long macapuy = ParamUtil.getLong(uploadReq, "capuy");
		long matongiao = ParamUtil.getLong(uploadReq, "tongiao");
		long maxuatthan = ParamUtil.getLong(uploadReq, "xuatthan");
		long magdpt = ParamUtil.getLong(uploadReq, "gdpt");
		long madanhhieu = ParamUtil.getLong(uploadReq, "danhhieu");
		long machucvu = ParamUtil.getLong(uploadReq, "chucvu");
		long madonvi = ParamUtil.getLong(uploadReq, "donvi");
		
		hoso hosoNew = null;
		if(idHoso.equals("0") || Validator.isNull(idHoso)){
			hosoNew = hosoLocalServiceUtil.addHoso(groupId, companyId, languageId, userId, shnv, cmtnd, hoten, 
					gioitinh, tenthuongdung, dateDOB, noisinh, quequan, diachithuongtru, diachitamtru, dienthoai, email, 
					quocgia, ngayVaoDang, cntn1, namtn1, cntn2, namtn2, cntn3, namtn3, madonvi, machucvu, madantoc, mahocham, 
					mahocvi, mahesoluong, macapuy, matongiao, maxuatthan, magdpt, madanhhieu, 0);
			
//			user.getExpandoBridge().setAttribute("idHoso", hosoNew.getMahoso());
		}else{
			hosoNew = hosoLocalServiceUtil.updateHoso(Long.valueOf(idHoso), shnv, cmtnd, hoten, gioitinh, tenthuongdung, dateDOB, noisinh, 
					quequan, diachithuongtru, diachitamtru, dienthoai, email, quocgia, ngayVaoDang, cntn1, namtn1, cntn2, namtn2, 
					cntn3, namtn3, madonvi, machucvu, madantoc, mahocham, mahocvi, mahesoluong, macapuy, matongiao, maxuatthan, 
					magdpt, madanhhieu, 0);
		}
		
		// upload file
				String imageUrl = "";
				String realPath = req.getPortletSession().getPortletContext().getRealPath("/") + "employee/";
		        String sourceFileName = null;
		        byte[] bytes = null;
		        String image = uploadReq.getFileName("hinhanh");
		        System.out.println("RealPath"+realPath);
		        if(Validator.isNotNull(image)){
		        try{
		             sourceFileName =uploadReq.getFileName("hinhanh");
		             System.out.println("File name :"  + sourceFileName);
		             File file = uploadReq.getFile("hinhanh");
		             try {      
		                bytes = FileUtil.getBytes(file);
		             } catch (IOException e2) {            
		                e2.printStackTrace();
		             }
		             File newFile=null;
		            
		             if ((bytes != null) && (bytes.length > 0)) {            
		             try {
		            	 newFile = new File(realPath+sourceFileName);
		            	 FileInputStream fileInputStream = new FileInputStream(file);
		            	 FileOutputStream fileOutputStream = new FileOutputStream(newFile);            
		            	 fileInputStream.read(bytes);               
		            	 fileOutputStream.write(bytes, 0, bytes.length);                   
		            	 fileOutputStream.close();
		            	 fileInputStream.close();
		            	 SessionMessages.add(req, "success");
		             }
		             catch (FileNotFoundException e) {
		            	 System.out.println("File Not Found.");               
		            	 e.printStackTrace();
		            	 SessionMessages.add(req, "error");
		             }
		             catch (IOException e1){
		            	 System.out.println("Error Reading The File.");
		            	 e1.printStackTrace();
		            	 SessionMessages.add(req, "error");
		             }
		             }	
		            
		        } catch (Exception e) {
		        	System.out.println("Exception::::"+e.getMessage());
		        	SessionMessages.add(req, "error");
		        }
		        	imageUrl = sourceFileName;
		        	if(hosoNew.getDuongdananh() != null){
		        		File file = new File(req.getPortletSession().getPortletContext().getRealPath("/") + "employee/" + hosoNew.getDuongdananh());
		        		file.delete();
		        	}
		        	hosoNew.setDuongdananh(imageUrl);
		        }else if(hosoNew.getDuongdananh() != null){
		        	hosoNew.setDuongdananh(hosoNew.getDuongdananh());
		        }
				hosoLocalServiceUtil.updatehoso(hosoNew, false);
				
				res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	/**
	 * 
	 * 
	 */
	public void assignUserName(ActionRequest req, ActionResponse res) throws SystemException, PortalException{
		long idHoso = ParamUtil.getLong(req, "idHoso");
		long userId = ParamUtil.getLong(req, "userId");
		
		hoso hs = hosoLocalServiceUtil.getByPrimaryKey(idHoso);
		hs.setUserId(userId);
		hosoLocalServiceUtil.updatehoso(hs, false);
		
		User user = UserLocalServiceUtil.getUser(userId);
		user.getExpandoBridge().setAttribute("idHoso", idHoso);
		
		System.out.println("IdHoso: " + idHoso + "User Id: "+ userId);
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	/**
	 * 
	 * 
	 */
	public void removeUserName(ActionRequest req, ActionResponse res) throws SystemException, PortalException{
		long idHoso = ParamUtil.getLong(req, "idHoso");
		hoso hs = hosoLocalServiceUtil.getByPrimaryKey(idHoso);
		
		long userId = hs.getUserId();
		User user = UserLocalServiceUtil.getUser(userId);
		user.getExpandoBridge().setAttribute("idHoso", 0);
		
		hs.setUserId(0);
		hosoLocalServiceUtil.updatehoso(hs, false);
		
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	/**
	 * 	Xóa hồ sơ cán bộ
	 * 
	 * 
	 */
	public void deleteProfile(ActionRequest req, ActionResponse res) throws NumberFormatException, PortalException, SystemException{
//		long userId = ParamUtil.getLong(req, "userId");
//		String[] userIds = StringUtil.split(ParamUtil.get(req, "allRowIds",StringPool.BLANK));
//		
//		if(Validator.isNotNull(userId)){
//			User userDeleted = UserLocalServiceUtil.getUser(userId);
//			long idHoso = (Long) userDeleted.getExpandoBridge().getAttribute("idHoso");
//			hoso hosoDeleted = hosoLocalServiceUtil.getByPrimaryKey(idHoso);
//			if(hosoDeleted != null){
//				hosoLocalServiceUtil.deletehoso(hosoDeleted);
//				userDeleted.getExpandoBridge().setAttribute("idHoso", 0l);
//			}
//		}
//		else{
//			for(int i = 0; i < userIds.length; i++){
//				User userDeleted = UserLocalServiceUtil.getUser(Long.valueOf(userIds[i]));
//				long idHoso = (Long) userDeleted.getExpandoBridge().getAttribute("idHoso");
//				hoso hosoDeleted = hosoLocalServiceUtil.getByPrimaryKey(idHoso);
//				if(hosoDeleted != null){
//					hosoLocalServiceUtil.deletehoso(hosoDeleted);
//					userDeleted.getExpandoBridge().setAttribute("idHoso", 0l);
//				}
//			}
//		}
		
		long idHoso = ParamUtil.getLong(req, "idHoso");
		String[] idHosoS = StringUtil.split(ParamUtil.get(req, "allRowIds",StringPool.BLANK));
		
		if(Validator.isNotNull(idHoso)){
			hoso hosoDeleted = hosoLocalServiceUtil.getByPrimaryKey(idHoso);
				hosoLocalServiceUtil.deletehoso(hosoDeleted);
		}
		else{
			for(int i = 0; i < idHosoS.length; i++){
				hoso hosoDeleted = hosoLocalServiceUtil.getByPrimaryKey(Long.valueOf(idHosoS[i]) );
					hosoLocalServiceUtil.deletehoso(hosoDeleted);
			}
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	/**
	 * 
	 * 
	 * 
	 */
	public void updateDepartment(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException{		
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		Layout layout = themeDisplay.getLayout();
		long groupId = layout.getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		long userId = themeDisplay.getUserId();
		
		UploadPortletRequest uploadReq = PortalUtil.getUploadPortletRequest(req);
		donvi dvtemp = new donviImpl();
		String idDonvi = ParamUtil.getString(uploadReq, "idDonvi");
		
		// Get Organization that added or updated information
//		long orgId = ParamUtil.getLong(uploadReq, "orgId");
//		Organization orgForm = OrganizationLocalServiceUtil.getOrganization(orgId);
		
		String tendonvi = ParamUtil.getString(uploadReq, "tendonvi");
		long donvicha = ParamUtil.getLong(uploadReq, "donvicha");
		String diachi = ParamUtil.getString(uploadReq, "diachi");
		String dienthoai = ParamUtil.getString(uploadReq, "dienthoai");
		String fax = ParamUtil.getString(uploadReq, "fax");
		String email = ParamUtil.getString(uploadReq, "email");
		String website = ParamUtil.getString(uploadReq, "website");
		String gioithieuchung = ParamUtil.getString(uploadReq, "gioithieuchung");
		
		dvtemp.setTendonvi(tendonvi);
		dvtemp.setDonvicha(donvicha);
		dvtemp.setDiachi(diachi);
		dvtemp.setDienthoai(dienthoai); 
		dvtemp.setFax(fax);
		dvtemp.setEmail(email);
		dvtemp.setWebsite(website);
		dvtemp.setGioithieuchung(gioithieuchung);
		dvtemp.setGroupId(groupId);
		dvtemp.setCompanyId(companyId);
		dvtemp.setLanguageId(languageId);
				
		donvi dv = null;
		
		if(idDonvi.equals("0") || Validator.isNull(idDonvi)){
			dv = donviLocalServiceUtil.addDonVi(dvtemp, userId);
//			orgForm.getExpandoBridge().setAttribute("idDonvi", dv.getPrimaryKey());
		}else{
			dv = donviLocalServiceUtil.getdonvi(Long.valueOf(idDonvi));
			dv.setDonvicha(donvicha);
			dv.setTendonvi(tendonvi);
			dv.setDiachi(diachi);
			dv.setDienthoai(dienthoai);
			dv.setFax(fax);
			dv.setEmail(email);
			dv.setWebsite(website);
			dv.setGioithieuchung(gioithieuchung);
			
			donviLocalServiceUtil.updatedonvi(dv, false);
		}
		
		// upload file
		String imageUrl = "";
		String realPath = req.getPortletSession().getPortletContext().getRealPath("/") + "department/";
        String sourceFileName = null;
        byte[] bytes = null;
        String image = uploadReq.getFileName("hinhanh");
        System.out.println("RealPath"+realPath);
        if(Validator.isNotNull(image)){
        try{
             sourceFileName =uploadReq.getFileName("hinhanh");
             System.out.println("File name :"  + sourceFileName);
             File file = uploadReq.getFile("hinhanh");
             try {      
                bytes = FileUtil.getBytes(file);
             } catch (IOException e2) {            
                e2.printStackTrace();
             }
             File newFile=null;
            
             if ((bytes != null) && (bytes.length > 0)) {            
             try {
            	 newFile = new File(realPath+sourceFileName);
            	 FileInputStream fileInputStream = new FileInputStream(file);
            	 FileOutputStream fileOutputStream = new FileOutputStream(newFile);            
            	 fileInputStream.read(bytes);               
            	 fileOutputStream.write(bytes, 0, bytes.length);                   
            	 fileOutputStream.close();
            	 fileInputStream.close();
            	 SessionMessages.add(req, "success");
             }
             catch (FileNotFoundException e) {
            	 System.out.println("File Not Found.");               
            	 e.printStackTrace();
            	 SessionMessages.add(req, "error");
             }
             catch (IOException e1){
            	 System.out.println("Error Reading The File.");
            	 e1.printStackTrace();
            	 SessionMessages.add(req, "error");
             }
             }	
            
        } catch (Exception e) {
        	System.out.println("Exception::::"+e.getMessage());
        	SessionMessages.add(req, "error");
        }
        	imageUrl = sourceFileName;
        	if(dv.getHinhanh() != null){
        		File file = new File(req.getPortletSession().getPortletContext().getRealPath("/") + "department/" + dv.getHinhanh());
        		file.delete();
        	}
        	dv.setHinhanh(imageUrl);
        }else if(dv.getHinhanh() != null){
        	dv.setHinhanh(dv.getHinhanh());
        }
		donviLocalServiceUtil.updatedonvi(dv);
		
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.donvi");
	}
	
	public void deleteDepartment(ActionRequest req, ActionResponse res) throws SystemException, PortalException{
		long madonvi = ParamUtil.getLong(req, "depId");
		List<hoso> hosoByDonVi = hosoLocalServiceUtil.getByDonVi(madonvi);
		if(hosoByDonVi.isEmpty()){
			donviLocalServiceUtil.deleteDonVi(madonvi);
		}else{
			return;
		}
//		List<donvi> donvis = donviLocalServiceUtil.getAll();
//		for(donvi dv : donvis){
//			donviLocalServiceUtil.deleteDonVi(dv);
//		}
		
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.donvi");
	}

	public void updateFunction(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		long userId = themeDisplay.getUserId();
		long groupId = themeDisplay.getLayout().getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		
		String idChucvu = ParamUtil.getString(req, "idChucvu"); 
		
		chucvu cvtemp = new chucvuImpl();
		String tenchucvu = ParamUtil.getString(req, "tenchucvu");
		cvtemp.setTenchucvu(tenchucvu);
		cvtemp.setGroupId(groupId);
		cvtemp.setCompanyId(companyId);
		cvtemp.setLanguageId(languageId);
		
		chucvu cv = null;
		if(idChucvu.equals("0") || Validator.isNull(idChucvu)){
			cv = chucvuLocalServiceUtil.addChucVu(cvtemp, userId);
		}else{
			cv = chucvuLocalServiceUtil.getChucvu(Long.valueOf(idChucvu));
			cv.setTenchucvu(tenchucvu);
			chucvuLocalServiceUtil.updatechucvu(cv, false);
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.chucvu");
	}
	
	public void deleteFunction(ActionRequest req, ActionResponse res) throws SystemException, PortalException{
		long machucvu = ParamUtil.getLong(req, "machucvu");
		List<hoso> hosoByChucVu = hosoLocalServiceUtil.getByChucVu(machucvu);
		if(hosoByChucVu.isEmpty()){
			chucvuLocalServiceUtil.deleteChucVu(machucvu);
		}else{
			return;
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.chucvu");
	}
	
	public void updateGeneral(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		long groupId = themeDisplay.getLayout().getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		long userId = themeDisplay.getUserId();
		
		int typeGeneral = ParamUtil.getInteger(req, "typeGeneral");
		String idGeneral = ParamUtil.getString(req, "idGeneral");
		String tab2 = "";
		
		if(typeGeneral == PortletKeysExt.ADD_KHOIDV){
			String tenKhoi = ParamUtil.getString(req, "tenkhoi");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			khoidonviquanly kdvql = new khoidonviquanlyImpl();
			kdvql.setTenkhoi(tenKhoi);
			kdvql.setGroupId(groupId);
			kdvql.setCompanyId(companyId);
			kdvql.setLanguageId(languageId);
			khoidonviquanlyLocalServiceUtil.addKhoiDV(kdvql, userId);
			}else{
				khoidonviquanly kdvql = khoidonviquanlyLocalServiceUtil.getkhoidonviquanly(Long.valueOf(idGeneral));
				kdvql.setTenkhoi(tenKhoi);
				kdvql = khoidonviquanlyLocalServiceUtil.updatekhoidonviquanly(kdvql, false);
			}
			tab2 = "khoidonvi";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_HOCHAM){
			String tenHocham = ParamUtil.getString(req, "tenhocham");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			hocham hocHam = new hochamImpl();
			hocHam.setTenhocham(tenHocham);
			hocHam.setGroupId(groupId);
			hocHam.setCompanyId(companyId);
			hocHam.setLanguageId(languageId);
			hochamLocalServiceUtil.addHocHam(hocHam, userId);
			}else{
				hocham hocHam = hochamLocalServiceUtil.gethocham(Long.valueOf(idGeneral));
				hocHam.setTenhocham(tenHocham);
				hocHam = hochamLocalServiceUtil.updatehocham(hocHam, false);
			}
			tab2 = "hocham";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_HOCVI){
			String tenHocvi = ParamUtil.getString(req, "tenhocvi");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			hocvi hocVi = new hocviImpl();
			hocVi.setTenhocvi(tenHocvi);
			hocVi.setGroupId(groupId);
			hocVi.setCompanyId(companyId);
			hocVi.setLanguageId(languageId);
			hocviLocalServiceUtil.addHocVi(hocVi, userId);
			}else{
				hocvi hocVi = hocviLocalServiceUtil.gethocvi(Long.valueOf(idGeneral));
				hocVi.setTenhocvi(tenHocvi);
				hocVi = hocviLocalServiceUtil.updatehocvi(hocVi, false);
			}
			tab2 = "hocvi";
		}

		if(typeGeneral == PortletKeysExt.ADD_CAPUY){
			String tencapuy = ParamUtil.getString(req, "tencapuy");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			capuy capUy = new capuyImpl();
			capUy.setTencapuy(tencapuy);
			capUy.setGroupId(groupId);
			capUy.setCompanyId(companyId);
			capUy.setLanguageId(languageId);
			capuyLocalServiceUtil.addCapUy(capUy, userId);
			}else{
				capuy capUy = capuyLocalServiceUtil.getcapuy(Long.valueOf(idGeneral));
				capUy.setTencapuy(tencapuy);
				capUy = capuyLocalServiceUtil.updatecapuy(capUy, false);
			}
			tab2 = "capuy";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_DANHHIEU){
			String tendanhhieu = ParamUtil.getString(req, "tendanhhieu");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			danhhieu danhHieu = new danhhieuImpl();
			danhHieu.setTendanhhieu(tendanhhieu);
			danhHieu.setGroupId(groupId);
			danhHieu.setCompanyId(companyId);
			danhHieu.setLanguageId(languageId);
			danhhieuLocalServiceUtil.addDanhHieu(danhHieu, userId);
			}else{
				danhhieu danhHieu = danhhieuLocalServiceUtil.getdanhhieu(Long.valueOf(idGeneral));
				danhHieu.setTendanhhieu(tendanhhieu);
				danhHieu = danhhieuLocalServiceUtil.updatedanhhieu(danhHieu, false);
			}
			tab2 = "danhhieu";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_DANTOC){
			String tendantoc = ParamUtil.getString(req, "tendantoc");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			dantoc danToc = new dantocImpl();
			danToc.setTendantoc(tendantoc);
			danToc.setGroupId(groupId);
			danToc.setCompanyId(companyId);
			danToc.setLanguageId(languageId);
			dantocLocalServiceUtil.addDanhToc(danToc, userId);
			}else{
				dantoc danToc = dantocLocalServiceUtil.getdantoc(Long.valueOf(idGeneral));
				danToc.setTendantoc(tendantoc);;
				danToc = dantocLocalServiceUtil.updatedantoc(danToc, false);
			}
			tab2 = "dantoc";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_TONGIAO){
			String tentongiao = ParamUtil.getString(req, "tentongiao");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			tongiao tonGiao = new tongiaoImpl();
			tonGiao.setTentongiao(tentongiao);
			tonGiao.setGroupId(groupId);
			tonGiao.setCompanyId(companyId);
			tonGiao.setLanguageId(languageId);
			tongiaoLocalServiceUtil.addTonGiao(tonGiao, userId);
			}else{
				tongiao tonGiao = tongiaoLocalServiceUtil.gettongiao(Long.valueOf(idGeneral));
				tonGiao.setTentongiao(tentongiao);
				tonGiao = tongiaoLocalServiceUtil.updatetongiao(tonGiao, false);
			}
			tab2 = "tongiao";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_XUATTHAN){
			String tenxuatthan = ParamUtil.getString(req, "tenxuatthan");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			xuatthan xt = new xuatthanImpl();
			xt.setTenxuatthan(tenxuatthan);
			xt.setGroupId(groupId);
			xt.setCompanyId(companyId);
			xt.setLanguageId(languageId);
			xuatthanLocalServiceUtil.addXuatThan(xt, userId);
			}else{
				xuatthan xt = xuatthanLocalServiceUtil.getxuatthan(Long.valueOf(idGeneral));
				xt.setTenxuatthan(tenxuatthan);
				xt = xuatthanLocalServiceUtil.updatexuatthan(xt, false);
			}
			tab2 = "xuatthan";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_GDPT){
			String tengdpt = ParamUtil.getString(req, "tengdpt");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			giaoducphothong gdpt = new giaoducphothongImpl();
			gdpt.setTengdpt(tengdpt);
			gdpt.setGroupId(groupId);
			gdpt.setCompanyId(companyId);
			gdpt.setLanguageId(languageId);
			giaoducphothongLocalServiceUtil.addGDPT(gdpt, userId);
			}else{
				giaoducphothong gdpt = giaoducphothongLocalServiceUtil.getgiaoducphothong(Long.valueOf(idGeneral));
				gdpt.setTengdpt(tengdpt);
				gdpt = giaoducphothongLocalServiceUtil.updategiaoducphothong(gdpt, false);
			}
			tab2 = "giaoducphothong";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_NGACHLUONG){
			String tenngachluong = ParamUtil.getString(req, "tenngachluong");
			long mangachluong = ParamUtil.getLong(req, "mangachluong");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			ngachluong ngachLuong = new ngachluongImpl();
			ngachLuong.setMangachluong(mangachluong);
			ngachLuong.setTenngachluong(tenngachluong);
			ngachLuong.setGroupId(groupId);
			ngachLuong.setCompanyId(companyId);
			ngachLuong.setLanguageId(languageId);
			ngachluongLocalServiceUtil.addNgachLuong(ngachLuong, userId);
			}else{
				ngachluong ngachLuong = ngachluongLocalServiceUtil.getngachluong(Long.valueOf(idGeneral));
				ngachLuong.setMangachluong(mangachluong);
				ngachLuong.setTenngachluong(tenngachluong);
				ngachLuong = ngachluongLocalServiceUtil.updatengachluong(ngachLuong, false);
			}
			tab2 = "ngachluong";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_HESOLUONG){
			double hesoluong = ParamUtil.getDouble(req, "hesoluong");
			double bacluong = ParamUtil.getDouble(req, "bacluong");
			long ngachluong = ParamUtil.getLong(req, "ngachluong");
			if(Validator.equals(idGeneral, "0") || Validator.isNull(idGeneral)){
			hesoluong hsl = new hesoluongImpl();
			hsl.setHesoluong(hesoluong);
			hsl.setBacluong(bacluong);
			hsl.setMangachluong(ngachluong);
			hsl.setGroupId(groupId);
			hsl.setCompanyId(companyId);
			hsl.setLanguageId(languageId);
			hesoluongLocalServiceUtil.addHeSoLuong(hsl, userId);
			}else{
				hesoluong hsl = hesoluongLocalServiceUtil.gethesoluong(Long.valueOf(idGeneral));
				hsl.setHesoluong(hesoluong);
				hsl.setBacluong(bacluong);
				hsl.setMangachluong(ngachluong);
				hsl = hesoluongLocalServiceUtil.updatehesoluong(hsl, false);
			}
			tab2 = "hesoluong";
		}
		
		
		String tabRender = "/html/manage_employee/view.jsp?tab1=tab.qlcb.qlychung&tab2=" + tab2;
		
		res.setRenderParameter("jspPage", tabRender);
	
	}
	
	public void deleteGeneral(ActionRequest req, ActionResponse res) throws NumberFormatException, SystemException, PortalException{
		
		int typeGeneral = ParamUtil.getInteger(req, "typeGeneral");
		String idGeneral = ParamUtil.getString(req, "idGeneral");
		String tab2 = "";
		
		if(typeGeneral == PortletKeysExt.ADD_KHOIDV){
			long idKhoiDV = Long.valueOf(idGeneral);
			List<donvi> donviByKhoiDV = donviLocalServiceUtil.getByKhoiDV(idKhoiDV);
			if(donviByKhoiDV.isEmpty()){
				khoidonviquanlyLocalServiceUtil.deleteKhoiDV(idKhoiDV);
			}else{
				return;
			}
			tab2 = "khoidonvi";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_HOCHAM){
			long idHocHam = Long.valueOf(idGeneral);
			List<hoso> hosoByHocHam = hosoLocalServiceUtil.getByHocHam(idHocHam);
			if(hosoByHocHam.isEmpty()){
				hochamLocalServiceUtil.deleteHocHam(idHocHam);
			}else{
				return;
			}
			tab2 = "hocham";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_HOCVI){
			long idHocVi =  Long.valueOf(idGeneral);
			List<hoso> hosoByHocVi = hosoLocalServiceUtil.getByHocVi(idHocVi);
			if(hosoByHocVi.isEmpty()){
				hocviLocalServiceUtil.deleteHocVi(idHocVi);
			}else{
				return;
			}
			tab2 = "hocvi";
		}

		if(typeGeneral == PortletKeysExt.ADD_CAPUY){
			long idCapUy =  Long.valueOf(idGeneral);
			List<hoso> hosoByCapUy = hosoLocalServiceUtil.getByCapUY(idCapUy);
			if(hosoByCapUy.isEmpty()){
				capuyLocalServiceUtil.deleteCapUy(idCapUy);
			}
			tab2 = "capuy";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_DANHHIEU){
			long idDanhHieu = Long.valueOf(idGeneral);
			List<hoso> hosoByDanhHieu = hosoLocalServiceUtil.getByDanhHieu(idDanhHieu);
			if(hosoByDanhHieu.isEmpty()){
				danhhieuLocalServiceUtil.deleteDanhHieu(idDanhHieu);
			}
			tab2 = "danhhieu";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_DANTOC){
			long idDanToc = Long.valueOf(idGeneral);
			List<hoso> hosoByDanToc = hosoLocalServiceUtil.getByDanToc(idDanToc);
			if(hosoByDanToc.isEmpty()){
				dantocLocalServiceUtil.deleteDantoc(idDanToc);
			}
			tab2 = "dantoc";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_TONGIAO){
			long idTonGiao = Long.valueOf(idGeneral);
			List<hoso> hosoByTonGiao = hosoLocalServiceUtil.getByTonGiao(idTonGiao);
			if(hosoByTonGiao.isEmpty()){
				tongiaoLocalServiceUtil.deleteTonGiao(idTonGiao);
			}
			tab2 = "tongiao";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_XUATTHAN){
			long idXuatthan = Long.valueOf(idGeneral);
			List<hoso> hosoByXuatthan = hosoLocalServiceUtil.getByXuatThan(idXuatthan);
			if(hosoByXuatthan.isEmpty()){
				xuatthanLocalServiceUtil.deleteXuatThan(idXuatthan);
			}
			tab2 = "xuatthan";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_GDPT){
			long idGDPT = Long.valueOf(idGeneral);
			List<hoso> hosoByGDPT = hosoLocalServiceUtil.getByGDPT(idGDPT);
			if(hosoByGDPT.isEmpty()){
				giaoducphothongLocalServiceUtil.deleteGDPT(idGDPT);
			}			
			tab2 = "giaoducphothong";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_NGACHLUONG){
			long idNgachLuong = Long.valueOf(idGeneral);
			ngachluong ngachLuong = ngachluongLocalServiceUtil.getngachluong(idNgachLuong);
			List<hesoluong> hslByNgachLuong = hesoluongLocalServiceUtil.getByNgachLuong(ngachLuong.getMangachluong());
			if(hslByNgachLuong.isEmpty()){
				ngachluongLocalServiceUtil.deleteNgachLuong(idNgachLuong);
			}
			tab2 = "ngachluong";
		}
		
		if(typeGeneral == PortletKeysExt.ADD_HESOLUONG){
			long idHesoluong = Long.valueOf(idGeneral);
			List<hoso> hosoByHesoluong = hosoLocalServiceUtil.getByHeSoLuong(idHesoluong);
			if(hosoByHesoluong.isEmpty()){
				hesoluongLocalServiceUtil.deleteHeSoLuong(idHesoluong);
			}
			tab2 = "hesoluong";
		}
		
		
		String tabRender = "/html/manage_employee/view.jsp?tab1=tab.qlcb.qlychung&tab2=" + tab2;
		
		res.setRenderParameter("jspPage", tabRender);
	}
	
	public void updateDBHH(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		long userId = themeDisplay.getUserId();
		long groupId = themeDisplay.getLayout().getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		
		String madbhh = ParamUtil.getString(req, "madbhh");
		long mahoso = ParamUtil.getLong(req, "mahoso");
		long mahocham = ParamUtil.getLong(req, "mahocham");
		String chuyennganh = ParamUtil.getString(req, "chuyennganh");
		int namphong = ParamUtil.getInteger(req, "namphong");
		
		dienbienhocham dbhhTemp = new dienbienhochamImpl();
		dbhhTemp.setMahocham(mahocham);
		dbhhTemp.setChuyennganh(chuyennganh);
		dbhhTemp.setNamphong(namphong);
		dbhhTemp.setMahoso(mahoso);
		dbhhTemp.setGroupId(groupId);
		dbhhTemp.setCompanyId(companyId);
		dbhhTemp.setLanguageId(languageId);
		
		if(madbhh.equals("0") || Validator.isNull(madbhh)){
			dienbienhochamLocalServiceUtil.addDBHH(dbhhTemp, userId);
		}else{
			dienbienhochamLocalServiceUtil.updateDBHH(Long.valueOf(madbhh), mahocham, chuyennganh, namphong);
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	public void updateDBHV(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		long userId = themeDisplay.getUserId();
		long groupId = themeDisplay.getLayout().getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		
		String madbhv = ParamUtil.getString(req, "madbhv");
		long mahoso = ParamUtil.getLong(req, "mahoso");
		long mahocvi = ParamUtil.getLong(req, "mahocvi");
		String chuyennganh = ParamUtil.getString(req, "chuyennganh");
		int namphong = ParamUtil.getInteger(req, "namphong");
		
		dienbienhocvi dbhvTemp = new dienbienhocviImpl();
		dbhvTemp.setMahocvi(mahocvi);
		dbhvTemp.setChuyennganh(chuyennganh);
		dbhvTemp.setNamphong(namphong);
		dbhvTemp.setMahoso(mahoso);
		dbhvTemp.setGroupId(groupId);
		dbhvTemp.setCompanyId(companyId);
		dbhvTemp.setLanguageId(languageId);
		
		if(madbhv.equals("0") || Validator.isNull(madbhv)){
			dienbienhocviLocalServiceUtil.addDBHV(dbhvTemp, userId);
		}else{
			dienbienhocviLocalServiceUtil.updateDBHV(Long.valueOf(madbhv), mahocvi, chuyennganh, namphong);
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	public void updateDBL(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException, ParseException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		long userId = themeDisplay.getUserId();
		long groupId = themeDisplay.getLayout().getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		
		String madbl = ParamUtil.getString(req, "madbl");
		long mahoso = ParamUtil.getLong(req, "mahoso");
		long mahsl = ParamUtil.getLong(req, "mahsl");
		
		String fromDateS = req.getParameter("dayFromDate") + "/" + req.getParameter("monthFromDate") + "/" + req.getParameter("yearFromDate");
		Date fromDate = dateFormat.parse(fromDateS);
		String toDateS = req.getParameter("dayToDate") + "/" + req.getParameter("monthToDate") + "/" + req.getParameter("yearToDate");
		Date toDate = dateFormat.parse(toDateS);
		
		dienbienluong dblTemp = new dienbienluongImpl();
		dblTemp.setMahesoluong(mahsl);
		dblTemp.setMahoso(mahoso);
		dblTemp.setGroupId(groupId);
		dblTemp.setCompanyId(companyId);
		dblTemp.setLanguageId(languageId);
		dblTemp.setTungay(fromDate);
		dblTemp.setDenngay(toDate);
		
		if(madbl.equals("0") || Validator.isNull(madbl)){
			dienbienluongLocalServiceUtil.addDBL(dblTemp, userId);
		}else{
			dienbienluongLocalServiceUtil.updateDBL(Long.valueOf(madbl), mahsl, fromDate, toDate);
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	public void updateQTDNN(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException, ParseException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		long userId = themeDisplay.getUserId();
		long groupId = themeDisplay.getLayout().getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		
		String maqtdnn = ParamUtil.getString(req, "maqtdnn");
		long mahoso = ParamUtil.getLong(req, "mahoso");
		String quocgia = ParamUtil.getString(req, "quocgia");
		String mucdich = ParamUtil.getString(req, "mucdich");
		
		String fromDateS = req.getParameter("dayFromDate") + "/" + req.getParameter("monthFromDate") + "/" + req.getParameter("yearFromDate");
		Date fromDate = dateFormat.parse(fromDateS);
		String toDateS = req.getParameter("dayToDate") + "/" + req.getParameter("monthToDate") + "/" + req.getParameter("yearToDate");
		Date toDate = dateFormat.parse(toDateS);
		
		quatrinhdinuocngoai qtdnnTemp = new quatrinhdinuocngoaiImpl();
		qtdnnTemp.setQuocgia(quocgia);
		qtdnnTemp.setMucdich(mucdich);
		qtdnnTemp.setTungay(fromDate);
		qtdnnTemp.setDenngay(toDate);
		qtdnnTemp.setMahoso(mahoso);
		qtdnnTemp.setGroupId(groupId);
		qtdnnTemp.setCompanyId(companyId);
		qtdnnTemp.setLanguageId(languageId);
		
		if(maqtdnn.equals("0") || Validator.isNull(maqtdnn)){
			quatrinhdinuocngoaiLocalServiceUtil.addQTDNN(qtdnnTemp, userId);
		}else{
			quatrinhdinuocngoaiLocalServiceUtil.updateQTDNN(Long.valueOf(maqtdnn), fromDate, toDate, quocgia, mucdich);
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
	
	public void updateQTNC(ActionRequest req, ActionResponse res) throws SystemException, NumberFormatException, PortalException, ParseException{
		ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
		long userId = themeDisplay.getUserId();
		long groupId = themeDisplay.getLayout().getGroupId();
		long companyId = themeDisplay.getCompanyId();
		String languageId = themeDisplay.getLanguageId();
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		
		String maqnc = ParamUtil.getString(req, "maqnc");
		long mahoso = ParamUtil.getLong(req, "mahoso");
		String tendetai = ParamUtil.getString(req, "tendetai");
		
		String fromDateS = req.getParameter("dayFromDate") + "/" + req.getParameter("monthFromDate") + "/" + req.getParameter("yearFromDate");
		Date fromDate = dateFormat.parse(fromDateS);
		String toDateS = req.getParameter("dayToDate") + "/" + req.getParameter("monthToDate") + "/" + req.getParameter("yearToDate");
		Date toDate = dateFormat.parse(toDateS);
		
		quatrinhnghiencuu qtnc = new quatrinhnghiencuuImpl();
		qtnc.setTendetai(tendetai);
		qtnc.setTungay(fromDate);
		qtnc.setDenngay(toDate);
		qtnc.setMahoso(mahoso);
		qtnc.setGroupId(groupId);
		qtnc.setCompanyId(companyId);
		qtnc.setLanguageId(languageId);
		
		if(maqnc.equals("0") || Validator.isNull(maqnc)){
			quatrinhnghiencuuLocalServiceUtil.addQTNC(qtnc, userId);
		}else{
			quatrinhnghiencuuLocalServiceUtil.updateQTNC(Long.valueOf(maqnc), tendetai, fromDate, toDate);
		}
		res.setRenderParameter("jspPage", "/html/manage_employee/view.jsp?tab1=tab.qlcb.canbo");
	}
}


















